package com.bytedance.improvingroad.recyclerview

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout

/**
 * Created by chenxiong
 * date 11/26/21
 */

/*
    将每一个item抽离成一个具体的View，只需继承BaseCustomView，提供布局ID、具体的数据绑定
    如binding.textView = data.text


 */
abstract class BaseCustomView<DATA : IBaseCustomViewModel> @JvmOverloads constructor(
    context: Context,
    attr: AttributeSet? = null, style: Int = 0
) : FrameLayout(context, attr, style), ICustomView<DATA> {
    protected lateinit var view: View

    init {
        init()
    }

    private fun init() {
        view = LayoutInflater.from(context).inflate(getLayoutId(),this,false)
        addView(view)
    }
    abstract fun getLayoutId(): Int

    override fun setData(data: DATA) {
        setDataToView(data)
    }

    protected abstract fun setDataToView(data: DATA)

}